<template>
  <div>
    <el-table :data="tableData" border stripe style="width: 100%; margin-top: 10px">
      <el-table-column label="鲜花名称">
        <template slot-scope="scope">
          <a :href="['/front/goods?id=' + scope.row.goodsId]">{{ scope.row.goodsName }}</a>
        </template>
      </el-table-column>
      <el-table-column prop="goodsImg" label="鲜花图片">
        <template slot-scope="scope">
          <el-image :src="scope.row.goodsImg" :preview-src-list="[scope.row.goodsImg]" style="width: 100%; height: 100px" fit="contain"></el-image>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="收藏时间"></el-table-column>

      <el-table-column
          fixed="right"
          label="操作"
          width="200">
        <template slot-scope="scope">

          <el-popconfirm
              @confirm="del(scope.row.id)"
              title="确定取消收藏吗？"
          >
            <el-button type="danger" slot="reference" style="margin-left: 10px">取消收藏</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin-top: 10px; background-color: white; padding: 10px 0;">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-size="pageSize"
        :page-sizes="[2, 5, 10]"
        layout="prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import API from '../../utils/request'
const url = "/api/collect/"

export default {
  name: "Collect",
  data() {
    return {
      fileList: [],
      options: [],
      text: '',
      user: {},
      tableData: [],
      pageNum: 1,
      pageSize: 10,
      entity: {},
      total: 0,
      dialogFormVisible: false
    };
  },
  created() {
    this.user = sessionStorage.getItem("user") ? JSON.parse(sessionStorage.getItem("user")) : {}
    this.$emit('user', this.user);
    this.load()
  },
  methods: {
    fileSuccessUpload(res) {
      this.entity.file = "http://localhost:9999/files/" + res.data;
      this.fileList = [res.data]
      console.log(res)
    },
    handleSizeChange(pageSize) {
      this.pageSize = pageSize
      this.load()
    },
    handleCurrentChange(pageNum) {
      this.pageNum = pageNum
      this.load()
    },
    load() {
       API.get(url + "/page/front", {
          params: {
            pageNum: this.pageNum,
            pageSize: this.pageSize,
            name: this.text
          }
       }).then(res => {
          this.tableData = res.data.records || []
          this.total = res.data.total
       })
    },
    del(id) {
      API.delete(url + id).then(res => {
        this.$message({
          type: "success",
          message: "操作成功"
        })
        this.load()
      })
    }
  },
};
</script>

<style scoped>
</style>
